package com.ruoyi.system.service.impl;

import com.ruoyi.system.mapper.StuTaskMapper;
import com.ruoyi.system.pojo.NewStuDetail;
import com.ruoyi.system.pojo.StuDetail;
import com.ruoyi.system.pojo.StuList;
import com.ruoyi.system.service.StuTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.ui.ModelMap;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class StuTaskServiceImpl implements StuTaskService {
    @Autowired
    private StuTaskMapper stuTaskMapper;

    //返回学生列表的数据
    @Override
    public List<StuList> stuList() {
        return stuTaskMapper.stuList();
    }

    //新增学生界面保存接口
    @Override
    public void addStu(NewStuDetail newStuDetail) {
        stuTaskMapper.addStu(newStuDetail);
    }

    //编辑学生(通过学号获取信息)
    @Override
    public StuDetail findStudentByXh(Long xh) {
        return stuTaskMapper.findStudentByXh(xh);
    }

    //编辑学生(按钮)
    @Override
    public void update(StuDetail stuDetail) {
        Date now = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String dateString = formatter.format(now);
        StuList stuList = new StuList();
        stuList.setXgrq(dateString);

        stuTaskMapper.update(stuDetail);
    }

    //返回详情数据（通过学号）
    @Override
    public List<StuDetail> stuDetail(Long xh) {
        return stuTaskMapper.stuDetail(xh);
    }

}
